package com.rede.didiok.admin.restapi.admin;


import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.admin.annotion.AuthorityVerify.AuthorityVerify;
import com.rede.didiok.admin.annotion.OperationLogger.OperationLogger;
import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.user.NoticeDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.UserFeignClient;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;

/**
 * 通知表 RestApi
 *
 * @author Rede
 * @date 2023年10月6日00:03:08
 */
@RestController
@Api(value = "通知相关接口", tags = {"通知相关接口"})
@RequestMapping("/admin/notice")
@Slf4j
public class NoticeRestApi {

    @Autowired
    UserFeignClient userFeignClient;

    @AuthorityVerify
    @ApiOperation(value = "获取通知列表", notes = "获取通知列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody NoticeDto noticeDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        log.info("获取通知列表");
        return userFeignClient.getNoticePageList(noticeDto);
    }

    @AvoidRepeatableCommit
    @AuthorityVerify
    @OperationLogger(value = "增加通知")
    @ApiOperation(value = "增加通知", notes = "增加通知", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody NoticeDto noticeDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.addNotice(noticeDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "编辑通知")
    @ApiOperation(value = "编辑通知", notes = "编辑通知", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody NoticeDto noticeDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.editNotice(noticeDto);
    }

    @OperationLogger(value = "删除通知")
    @ApiOperation(value = "删除通知", notes = "删除通知", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody NoticeDto noticeDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.deleteNotice(noticeDto);
    }

    @ApiOperation(value = "获取后台站内信列表", notes = "获取后台站内信列表", response = String.class)
    @PostMapping("/getBackNoticeList")
    public String getBackNoticeList(@RequestBody NoticeDto noticeDto, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.getBackNoticeList(noticeDto);
    }

    @OperationLogger(value = "批量删除后台通知")
    @ApiOperation(value = "批量删除后台通知", notes = "批量删除后台通知", response = String.class)
    @PostMapping("/deleteBatchBlackNotice")
    public String deleteBatchBlackNotice(@Validated({Delete.class}) @RequestBody List<NoticeDto> noticeDtoList, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.deleteBatchNotice(noticeDtoList);
    }

    @OperationLogger(value = "删除站内信小红点提示")
    @ApiOperation(value = "删除站内信小红点提示", notes = "删除站内信小红点提示", response = String.class)
    @PostMapping("/deleteRedisBatchNotice")
    public String deleteRedisBatchNotice() {
        userFeignClient.deleteRedisBatchNotice();
        return ResultUtil.successWithData("删除小红点提示成功");
    }

    @ApiOperation(value = "获取后台站内信消息数量", notes = "获取后台站内信消息数量", response = String.class)
    @PostMapping("/searchAllNoticeCount")
    public String searchAllNoticeCount() {
        return userFeignClient.searchAllNoticeCount();
    }
}